﻿// <copyright file="PackageFileGuidTable.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;
    using System.Collections.Generic;
    using System.IO;

    public class PackageFileGuidTable : System.Collections.ObjectModel.KeyedCollection<Guid, _PACKAGE_FILE_GUID_INFO>
    {
        /// <summary>
        /// Initializes a new instance of the PackageFileGuidTable class.
        /// </summary>
        public PackageFileGuidTable(System.IO.BinaryReader fileReader)
        {
            this.ReadContainer(fileReader);
        }

        protected override Guid GetKeyForItem(_PACKAGE_FILE_GUID_INFO item)
        {
            return item.FileGuid;
        }

        /// <summary>
        /// Reads the actual data for this container from the file.
        /// </summary>
        protected void ReadContainer(System.IO.BinaryReader fileReader)
        {
            _PACKAGE_FILE_GUID_INFO pfgi;
            do
            {
                pfgi = new _PACKAGE_FILE_GUID_INFO(fileReader);
                if (!pfgi.FileGuid.Equals(Guid.Empty))
                {
                    this.Add(pfgi);
                }
            }
            while ((fileReader.BaseStream.Length > fileReader.BaseStream.Position));
        }
    }
}
